package com.ruoyi.yljf.controller.AppController;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.security.annotation.Anonymous;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.yljf.domain.BookChapter;
import com.ruoyi.yljf.domain.enums.yljfEnums;
import com.ruoyi.yljf.domain.vo.BookChapterVO;
import com.ruoyi.yljf.service.IBookChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 章节内容Controller
 * 
 * @author metaee
 * @date 2025-02-12
 */
@Anonymous
@RestController
@RequestMapping("api/chapter")
public class ApiBookChapterController extends BaseController {
    @Autowired
    private IBookChapterService bookChapterService;

    /**
     * 查询章节内容列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BookChapter bookChapter) {
        startPage();
        List<BookChapterVO> list = bookChapterService.selectBookChapterList(bookChapter);
        return getDataTable(list);
    }

    /**
     * 获取章节内容详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        BookChapter bookChapter = bookChapterService.getById(id);
        BookChapterVO bookChapterVO = new BookChapterVO(bookChapter);
        bookChapterVO.setFree(yljfEnums.descOfCode(bookChapter.getFree()));
        return success();
    }

    
}
